//
//  DKUnauthorizeHomeViewController.m
//  DanKU
//
//  Created by 吴斌 on 2023/9/26.
//

#import "DKUnauthorizeHomeViewController.h"
#import "DKHomeUnauthorizeHeadView.h"
#import "DKHomeUnauthorizeBottomView.h"
#import "DKTabBarViewController.h"
#import "DKTabBarViewController.h"
#import "DKHomeHttp.h"
#import "DKAuthStepViewController.h"
@interface DKUnauthorizeHomeViewController ()
@property (nonatomic, strong)DKHomeUnauthorizeHeadView * dk_HomeUnauthorizeHeadView;
@property (nonatomic, strong)DKHomeUnauthorizeBottomView * dk_HomeUnauthorizeBottomView;
@end

@implementation DKUnauthorizeHomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = UIColor.whiteColor;
    [self dk_creatView];
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self updataNextStepStatus];
}
- (void)updataNextStepStatus{
    WeakSelf(self)
    //获取用户状态
    [DKPublicHttp apiGetNextStepForAPI:@{} complete:^{
        if([[DKGlobalHelper defaultManager].loanSetpInfoMdl.step isEqualToString:@"100"]){//已经成功认证
            DKTabBarViewController * dk_TabBarViewCtrl = [[DKTabBarViewController alloc] init];
            dk_TabBarViewCtrl.isAuth = YES;
            ((AppDelegate*)([UIApplication sharedApplication].delegate)).window.rootViewController = dk_TabBarViewCtrl;
        }else{
            [weakSelf requestUserBrhavRecord:DK_ActionEnter withParmDic:@{}];

            //获取用户信息
            [DKHomeHttp apiGetUserBaseInfoForAPI:@{} complete:^{
                            
            }];
            //获取用户额度
            [DKHomeHttp apiGetUserCreditInfoForAPI:@{} complete:^{
                [weakSelf refushUnauthoriData];
            }];
            
        }
//        //获取拓展信息
        [[DKAuthExtHelper defaultManager] checkExtExpired];
        //保存登录时间戳
        DK_SETObject_USERDEF(NSUserDefault_LastHone, [NSString getCurrentTimeTimestamp]);
    }];
}
- (void)dk_creatView{
    WeakSelf(self)
    self.dk_HomeUnauthorizeHeadView = [[DKHomeUnauthorizeHeadView alloc] init];
    [self.view addSubview:self.dk_HomeUnauthorizeHeadView ];
    [self.dk_HomeUnauthorizeHeadView  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(0)));
        make.height.equalTo(@(DK_IsWidthScale(338)));
    }];
    self.dk_HomeUnauthorizeBottomView = [[DKHomeUnauthorizeBottomView alloc] init];
    [self.view addSubview:self.dk_HomeUnauthorizeBottomView];
    [self.dk_HomeUnauthorizeBottomView  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(0)));
        make.right.equalTo(@(DK_IsWidthScale(0)));
        make.top.equalTo(@(DK_IsWidthScale(267)));
        make.bottom.equalTo(@(DK_IsWidthScale(0)));
    }];
    self.dk_HomeUnauthorizeBottomView.HomeStartAuthBlock = ^{//首页开始认证
        [weakSelf requestUserBrhavRecord:DK_ActionClick withParmDic:@{}];

        DKAuthStepViewController *dk_AuthStepViewCtrl = [[DKAuthStepViewController alloc] init];
        dk_AuthStepViewCtrl.hidesBottomBarWhenPushed = YES;
        [weakSelf.navigationController pushViewController:dk_AuthStepViewCtrl animated:YES];
    };
    self.dk_HomeUnauthorizeBottomView.CheckPrivacyBlock = ^{////查看隐私协议
        DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_PrivacyAgreement withIsNavBar:YES];
        [weakSelf.navigationController pushViewController:dk_WebViewCtrl animated:YES];
    };
}
- (void)refushUnauthoriData{
//    [self.dk_HomeUnauthorizeBottomView updataBottomData];
}
- (void)requestUserBrhavRecord:(NSString *)action withParmDic:(NSDictionary *)parmDic{
    [DKPublicHttp apiUserBrhavRecordForAPI:parmDic withPageName:DK_Home withAction:action complete:^{
            
    } fail:^{
            
    }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
